const util = require('../../../util/util.js')
Page({
  // onShareAppMessage() {
  //   return {
  //     title: 'tabs',
  //     path: 'page/weui/example/tabs/tabs'
  //   }
  // },
  data: {
    list: [
      {
        id: '1',
        name: '作业道路清单',
      }, {
        id: '0',
        name: '未作业道路清单',
      }],
    clientNo: 0,
    info: {}
  },
  onLoad: function (options) {
    this.setData({
      clientNo: options.clientNo
    })
    this.GetWorkRoad()
  },
  // 获取
  GetWorkRoad () {
    var that = this;
    const currentDate = new Date();
    currentDate.setDate(currentDate.getDate() - 1);
    var dateStr = util.formatDate(currentDate)

    console.log(dateStr)
    // var strURL = 'GetWorkRoadInfoAPP';
    // if (this.data.isWork === '0') {
    //   strURL = 'GetWorkNoRoadInfoAPP'
    // }..GetExcelCar4?area=00000&type=&date=2025-03-20
    wx.request({
      url: 'https://www.ejingyou.cn/ServerHuanwei/CompanyapiBDEapi/Vehicle/GetExcelCar4',
      data: {
        area: this.data.clientNo,
        date: dateStr,
        type: '',
      },
      header: {
        'content-type': 'application/json' // 默认值     
      },
      success: (res) => {
        res.data.forEach(element => {
          if (element.RGrade === '总计') {
            const rate = (parseFloat(element.WORKROADNUM) / parseFloat(element.ROADNUM)) * 100;
            that.setData({
              info: {
                "DATE": dateStr,
                "ROADNUM": element.ROADNUM,
                "WORKROADNUM": element.WORKROADNUM,
                "NOWORKROADNUM": element.NOWORKROADNUM,
                "RATE": rate.toFixed(2) + '%'
              }
            });
          }
        });

      }
    })
  },
  kindToggle (e) {
    const id = e.currentTarget.id;
    switch (id) {
      case '1':
        wx.navigateTo({
          url: '../roadTask/roadTask?isWork=1'
        })
        break;
        case '0':
        wx.navigateTo({
          url: '../roadTask/roadTask?isWork=0'
        })
        break;
      default:
        break;
    }
  },
  // table 方法
  // onRowClick (e) {
  //   console.log('单击列表行')
  //   console.log(e)
  // },
  // // tab 方法
  // onTabClick(e) {
  //   this.setData({
  //     dataTable: []
  //   });
  //   const index = e.detail.index
  //   this.setData({ 
  //     activeTab: index 
  //   })
  //   this.GetWorkRoad(this.data.tabs[index].title)
  // },
  // handleClick(e) {
  //   console.log('tab?')
  //   // wx.navigateTo({
  //   //   url: './webview',
  //   // })
  // }
})
